load MAT/WIOD.mat;
load('MAT/Step_2_firm_data_alpha4.mat');
%eval([strcat('load MAT/rho',rhoT,'eta',etaT,'lambda',lambdaT,'_psi',num2str(varphi),'_sigma',num2str(sigmaT),'/Step_3_alpha',num2str(alphaT),...
%         '_rho',rhoT,'.mat')]); 
       eval([strcat('load MAT/rho',rhoT,'eta',etaT,'lambda',lambdaT,'_psi',num2str(varphi),'_sigma',num2str(sigmaT),'/Step_4_setup_alpha',num2str(alphaT),...
         '_rho',rhoT,'_approx.mat')]); 
NT_sectors={'E','F','50','51','52','H','60','61','62','63','64',...
                        'J','70','71t74','L','M','N','O','P'}';
WIOD_sectors = {'AtB' , 'C' , '15t16' ,'17t18' , '19' , '20' , '21t22' ,...
    '23' , '24' , '25' ,'26', '27t28', '29' , '30t33' , '34t35' ,...
    '36t37', 'E' , 'F' , '50', '51', '52', 'H', '60', '61', '62', '63',...
    '64', '70', '71t74', 'M', 'N', 'O'}';                     
T = ones(J,1);
for i =1:J
    for j=1:size(NT_sectors,1)
        if isequal(WIOD_sectors{i},NT_sectors{j})
            T(i,1)=0;
        end
    end
end
repmat_T = repmat(T',[FI_J 1]);
firmsecD_T = firmsecD_sorted * T;
firmsecD_NT = firmsecD_sorted * (ones(J,1)-T);

VA_f_Stata_T = VA_f_Stata(firmsecD_T==1);
VA_f_Stata_NT = VA_f_Stata(firmsecD_NT==1);
w_T = VA_f_Stata_T/sum(VA_f_Stata_T);
w_NT = VA_f_Stata_NT/sum(VA_f_Stata_NT);
pi_l_f_T = pi_l_f(firmsecD_T==1);
pi_l_f_NT = pi_l_f(firmsecD_NT==1);;

bin=200;
pi_l_f_T_cdf = histcounts(pi_l_f_T,bin,'Normalization','cdf');
[share_bin,share_edge]=discretize(pi_l_f_T,bin);
for i=1:bin;
    w_pdf(:,i) = sum(w_T(share_bin==i));
end
w_cdf = cumsum(w_pdf);

figure(1)
plot(share_edge(2:end),pi_l_f_T_cdf,'r-',share_edge(2:end),w_cdf,'bo','LineWidth',2)
legend('Unweighted','Weighted','Location','SouthEast');
xlabel('Labor Share','Interpreter','Latex');
ylabel('Cumulated Share of Firms','Interpreter','Latex');
axis([0 1 0 1]);
saveas(gcf,'Figures/FigA1a.eps','epsc2');

pi_l_f_NT_cdf = histcounts(pi_l_f_NT,bin,'Normalization','cdf');
[share_bin,share_edge]=discretize(pi_l_f_NT,bin);
for i=1:bin;
    w_pdf(:,i) = sum(w_NT(share_bin==i));
end
w_cdf = cumsum(w_pdf);

figure(1)
plot(share_edge(2:end),pi_l_f_NT_cdf,'r-',share_edge(2:end),w_cdf,'bo','LineWidth',2)
legend('Unweighted','Weighted','Location','SouthEast');
xlabel('Labor Share','Interpreter','Latex');
ylabel('Cumulated Share of Firms','Interpreter','Latex');
axis([0 1 0 1]);
saveas(gcf,'Figures/FigA1b.eps','epsc2');
